<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<style type="text/css">
.table thead tr th,.table tbody tr td{text-align:center;}
.table tbody tr td input{ width:18px; text-align:center;}
.table thead tr th{ vertical-align:middle;}
</style>

<script type="text/javascript">
	$(document).ready(function(){
		$('.table > tbody > tr:odd ').css("background-color","#f5f5f5");
	})
</script>

<div><form method="post" action="<?php  echo URL::base() ?>returnedparcelsort/index">请输入批次号：<input id="select_pi" type="text" style="width:200px" name="select_pi">&nbsp;&nbsp;<input class="btn btn-info" type='submit' value='查询'></form></div>

<?php if(!empty($ops)):?>
<table style="table-layout:fixed;" border=1 cellpadding=10 width=99% class="table"><thead>
<tr style="background-color:#4EA392; font-weight:bold; color:#ffffff;">
<th style=" width: 15px; "><input type='checkbox' id='chooseall' checked=""/></th>
<th style=" width: 15px; ">序号</th>
<th style=" width: 70px; ">erp订单号</th>
<th style="width:55px;">ebay平台单号</th>
<th style=" width: 100px; ">物流渠道</th>
<th style="width:112px;">运单号</th>
<th style=" width: 45px; ">退件扫描人</th>
<th style=" width: 85px; ">扫描时间</th>
<th style=" width: 30px; ">质检人</th>
<th style=" width: 85px; ">质检时间</th>
<th style=" width: 66px;">sku</th>
<th style=" width: 60px;">sku名称</th>
<th style=" width: 60px; ">储位</th>
<th style=" width: 20px; ">数量</th>
<th sytle=" width: 50px; ">质检合格量</th>
<th style=" width: 75px;">不合格量</th>
<th>操作</th>
</tr>
</thead><tbody>
<?php $i=1;foreach($ops as $op):?>
<tr id="tr_<?php echo $op['returned_id']?>">
<td><?php if($op['status']==0){?><input type='checkbox' name='updateparcel' value="<?php echo $op['returned_id']?>" checked=""/><?php } ?></td>
<td><?php echo $i?></td>
<td style="display:none"><?php echo $op['returned_id']?></td>
<td style="word-wrap: break-word;"><?php echo $op['erp_orders_id']?></td>
<td style="word-wrap: break-word;"><?php echo $op['ebay_order_id']?></td>
<td style="word-wrap: break-word;"><?php echo $op['shipping_method']?></td>
<td style="word-wrap: break-word;"><?php echo $op['orders_shipping_code']?></td>
<td style="word-wrap: break-word;"><?php echo $op['saomiao_user']?></td>
<td><?php echo $op['saomiao_time']?></td>
<td style="word-wrap: break-word;"><?php echo $op['qc_user']?></td>
<td><?php echo $op['qc_time']?></td>
<td style="word-wrap: break-word;"><?php echo $op['sku']?></td>
<td style="word-wrap: break-word;"><?php echo $op['sku_name']?></td>
<td style="word-wrap: break-word;"><?php echo $op['sku_storage_position']?></td>
<td style="word-wrap: break-word;"><?php echo $op['sku_num']?></td>
<td style="word-wrap: break-word;"><input style="width:30px;" type='text' class='hege_num' value="<?php echo ($op['status']==0)?$op['sku_num']:$op['qualified_num'] ?>"></td>

<td>不合格数量<br /><input style="width:30px;" type='text'  class="error_num" value="<?php echo $op['failure_num']?>" <?php if($op['status']!=0)echo "readonly='true'";?>><br/>
备注<br /><input style="width:30px;" type='text' class="error_remark"  value="<?php echo $op['error_remark']?>"  ></td>

<td><?php if($op['status']==0){?>
<input type='button' value="放弃" style="width:48px;" class="fangqi btn btn-info"><?php }?></td>
</tr>
<?php $i++;endforeach;?>
</tbody>
</table>
<input value='一键提交' type='button' id="updateparcel" class="btn btn-info">
<?php endif;?>

<style>
input{width:60px}
</style>

<script type="text/javascript">
	$(document).ready(function(){
$("#select_pi").val('<?php echo (isset($select_pi) && $select_pi!='')?$select_pi:''; ?>');

	var availableTags = [<?php echo $batches;?>];
	$("#select_pi").autocomplete({
       source: availableTags
	});

		$(".error_num").blur(function(){
			var error_num = $.trim($(this).val());
			if(!(/^(\+|-)?\d+$/.test(error_num)) || error_num < 0){
			alert('错误，输入的值必须是非负整数,请重新修改');return false;
			}

			var zong = parseInt($(this).parent().prev().prev().text());
			if(parseInt(error_num)>zong){
			alert('错误，输入的不合格量大于总质检量');return false;

			}

			$(this).parent().prev().find(".hege_num").val(zong-parseInt(error_num));

		});

/*
		$(".tijiao").click(function(){
			var returned_id = $(this).parents('tr').children('td').eq(2).text();
			var hege_num = $(this).parent().prev().prev().find(".hege_num").val();
			var error_num = $(this).parent().prev().find(".error_num").val();
			var notice =20;
			//var hege_remark = $(this).parent().prev().prev().find(".hege_remark").val();
			var error_remark = $(this).parent().prev().find(".error_remark").val();

			if(!(/^(\+|-)?\d+$/.test(error_num)) || error_num < 0){
			alert('错误，输入的值必须是非负整数,请重新修改');return false;
			}

			if(!(/^(\+|-)?\d+$/.test(hege_num)) || error_num < 0){
			alert('错误，输入的值必须是非负整数,请重新修改');return false;
			}

			$.post(
				"<?php echo URL::base() ?>returnedparcelsort/update_parcel",
				{returned_id:returned_id,hege_num:hege_num,error_num:error_num,notice:notice,error_remark:error_remark},
				function(data){
						alert(data);
			});

		});*/


		$(".fangqi").click(function(){
			var returned_id = $(this).parents('tr').children('td').eq(2).text();
			var notice = 10;

			$.post(
				"<?php echo URL::base() ?>returnedparcelsort/update_parcel",
				{returned_id:returned_id,notice:notice},
				function(data){
					if(data=='ok'){
						alert('退件包裹里没有此sku，所以取消，拒绝处理成功');

					}else{
						alert(data);
					}
			});
				$(this).parents('tr').remove();

		});
$('#chooseall').click(function (){
	if($(this).prop('checked')){
		console.info($(this).prop('checked'));
		$("[name='updateparcel']").each(function(){
			$(this).prop("checked",'true');
			console.info($(this).prop('checked'));
		});
	}else{
		console.info($(this).prop('checked'));
		$("[name='updateparcel']").each(function(){
			$(this).removeProp("checked");
			console.info($(this).prop('checked'));
		});

	}
});
	//一键提交
$("#updateparcel").click(function(){

	$("[name='updateparcel']").each(function(){
		console.info($(this));
		var ischeck = $(this).prop('checked');
		console.info(ischeck);
		if(ischeck){
			//$(this).attr("checked",'true');
			var id = $(this).val();
			console.info(id);

			var hege_num = $(this).parents('tr').children('td').eq(15).find(".hege_num").val();
			var error_num = $.trim($(this).parents('tr').children('td').eq(16).find(".error_num").val());
			var error_remark = $.trim($(this).parents('tr').children('td').eq(16).find(".error_remark").val());
			var notice =20;

			if(!(/^(\+|-)?\d+$/.test(error_num)) || parseInt(error_num) < 0){
				alert('错误，输入的值必须是非负整数,请重新修改');return false;
			}

			if(!(/^(\+|-)?\d+$/.test(hege_num)) || parseInt(error_num) < 0){
				alert('错误，输入的值必须是非负整数,请重新修改');return false;
			}
			var btn= $(this).parents('tr').children('td').eq(17).find("input[type='button']");
			$.post('<?php echo URL::base() ?>returnedparcelsort/update_parcel',{returned_id:id,hege_num:hege_num,error_num:error_num,error_remark:error_remark,notice:notice},function(data){
				if(data=='保存成功!'){
					$("#tr_"+id+" td").css({"background-color":"rgb(188, 241, 174)"});
					btn.hide();


				}else{
					$("#tr_"+id+" td").css({"background-color":""});
				}

			});
			$(this).hide();
		}

 	});
});

});


</script>

